package com.zyf.chapter02.creation.singleton;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 一个单例的 Id 生成器
 * @author yifeng
 */
public class IdGenerator {
    private AtomicLong id = new AtomicLong(0);
    private static final IdGenerator instance = new IdGenerator();
    private IdGenerator() {}
    public static IdGenerator getInstance() {
        return instance;
    }

    public long getId() {
        return id.incrementAndGet();
    }

    public static void main(String[] args) {
        // 使用举例
        long id = IdGenerator.getInstance().getId();
    }
}
